package com.isoftstone.bank.controller.base;


import com.isoftstone.util.Const;
import com.isoftstone.util.VerifyCodeUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @描述：
 * @author：guoX
 * @date：2017/10/26
 */
@Controller
public class VerifyCodeController extends BaseController {


    @RequestMapping(value="/system/merchant/verifyCode")
    public void verifyCode(HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");
        //生成随机字串
        String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
        this.getSession().setAttribute(Const.SESSION_SECURITY_CODE,verifyCode);
        //生成图片
        int w = 100, h = 30;
        VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
    }
}
